﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Hosting.Class;
using HostingDomainWebsite;

namespace Hosting
{
    public partial class AddAdmin : System.Web.UI.Page
    {

        protected SiteMaster master;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Redirect("AdminLogin.aspx");
                return;
            }
            master = Page.Master as SiteMaster;
            master.setCurrentNav("Account", "AdminAddition");
        }

        /* addValid() method return:
         * 1: Validation is successful!
         * 10: Username input is null or not have value
         * 11: Username is less than 5 character
         * 12: Username is bigger than 50 character
         * 13: Username is have an special character, Valid: [a-zA-Z0-9]
         * 14: Username is existed
         * 20: Password input is null or not have value
         * 21: Password is less than 5 character
         * 22: Password is bigger than 100 character
         * 23: Password is not valid, Valid: [a-zA-Z0-9@!#$\'%^&*`~]
         * 24: Password and repassword is not match
         * 30: Email is not valid
         * 31: Email is too big
         * 40: Phone is null or not have value
         * 41: Phone must be number
         * 42: Phone is less than 10 character
         * 43: Phone is bigger than 15 character
         * 50: Address is too long
         */

        protected void Create_Click(object sender, EventArgs e)
        {
            Users users = new Users();
            int isValid = users.addValid(txtUsername.Value, txtPassword.Value, txtRePassword.Value, txtPhone.Value, txtEmail.Value, txtAddress.Value);
            if (isValid == 1)
            {

                int isInsert = users.Add(txtUsername.Value, txtPassword.Value, txtPhone.Value, txtEmail.Value, txtAddress.Value);
                if (isInsert == 0)
                {
                    master.getMessage("Data inserts successfully!", "notification success png_bg");
                }
                else
                {
                    master.getMessage("There is an error!", "notification error png_bg");
                }

            }
            else if (isValid == 10)
            {
                master.getMessageAttention("Username input is null or not have value");
            }
            else if (isValid == 11)
            {
                master.getMessageAttention("Username is less than 5 character");
            }
            else if (isValid == 12)
            {
                master.getMessageAttention("Username is bigger than 50 character");
            }
            else if (isValid == 13)
            {
                master.getMessageAttention("Username is have an special character, Valid: [a-zA-Z0-9]");
            }
            else if (isValid == 14)
            {
                master.getMessageAttention("Username is existed");
            }
            else if (isValid == 20)
            {
                master.getMessageAttention("Password input is null or not have value");
            }
            else if (isValid == 21)
            {
                master.getMessageAttention("Password is less than 5 character");
            }
            else if (isValid == 22)
            {
                master.getMessageAttention("Password is bigger than 100 character");
            }
            else if (isValid == 23)
            {
                master.getMessageAttention("Password is not valid, Valid: [a-zA-Z0-9@!#$\'%^&*`~]");
            }
            else if (isValid == 24)
            {
                master.getMessageAttention("Password and repassword is not match");
            }
            else if (isValid == 30)
            {
                master.getMessageAttention("Email is not valid");
            }
            else if (isValid == 31)
            {
                master.getMessageAttention("Email is too big");
            }
            else if (isValid == 40)
            {
                master.getMessageAttention("Phone is null or not have value");
            }
            else if (isValid == 41)
            {
                master.getMessageAttention("Phone must be number");
            }
            else if (isValid == 42)
            {
                master.getMessageAttention("Phone is less than 10 character");
            }
            else if (isValid == 43)
            {
                master.getMessageAttention("Phone is bigger than 15 character");
            }
            else if (isValid == 50)
            {
                master.getMessageAttention("Address is too long");
            }
        }

        protected void Reset_Click(object sender, EventArgs e)
        {
            txtUsername.Value = "";
            txtPassword.Value = "";
            txtRePassword.Value = "";
            txtPhone.Value = "";
            txtEmail.Value = "";
            txtAddress.Value = "";
        }

    }
}